home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 4 / Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso / Development / General / SC++ 7.0.2 Update / TCL Demos / NewClassDemo ƒ / Demo Sources / CDemoTable.cp next >
Encoding:
Text File  |  1994-04-14  |  5.5 KB  |  199 lines  |  [TEXT/KAHL]

  1.  /******************************************************************************
  2.  CDemoTable.c
  3.  
  4.         
  5.     SUPERCLASS = CTable
  6.     
  7.     Copyright © 1991 Symantec Corporation. All rights reserved.
  8.     
  9.     This is a demo of the TCL class CTable. CTable provides the
  10.     foundation for scrolling list and spreadsheet-like panes.
  11.     It provides only visual appearance - storage for the contents
  12.     of cells must be provided in CTable subclasses.
  13.     
  14.     CDemoTable doesn't store any data for the cells, but it does
  15.     show a way to provide some features not directly supported by 
  16.     CTable. It adds row and column headings, and a user interface
  17.     for resizing rows and columns. Undo for row and column resizing
  18.     is also supported.
  19.     
  20.     Printing the row and column headings, and row and column selection
  21.     via clicking in the label area is not supported.
  22.     
  23.     This class relies on CTableScroller and CTableLabels for support
  24.     for syncronized scrolling of the row and column labels.
  25.     
  26.  
  27.  ******************************************************************************/
  28.  
  29. #include "CDemoTable.h"
  30. #include "CTableLabels.h"
  31. #include "CTableScroller.h"
  32. #include "CWindow.h"
  33. #include "Commands.h"
  34.  
  35. #define kPlusCursor            1024        // resource ID of 'CURS' cursor
  36.  
  37. extern RgnHandle gUtilRgn;                // a global utility region
  38.  
  39. /******************************************************************************
  40.  IDemoTable
  41.  
  42.      Initialize the demo table.
  43. ******************************************************************************/
  44.  
  45. void CDemoTable::IDemoTable(CTableScroller *anEnclosure, CBureaucrat *aSupervisor,
  46.                     CTableLabels *rowLabels, CTableLabels *colLabels)
  47. {
  48.     Rect            delta;
  49.     
  50.         // call CTable's initialization method. Note that we set the
  51.         // size to zero, because we are going to fit it to its enclosure
  52.  
  53.     CTable::ITable(anEnclosure, aSupervisor, 0, 0, 0, 0,
  54.                     sizELASTIC, sizELASTIC);
  55.                     
  56.         // Fit it to its enclosing view, which is the CTableScroller
  57.                     
  58.     FitToEnclosure(TRUE, TRUE);
  59.     
  60.         // Move it down and to the right to make room for the row and col labels
  61.     
  62.     SetRect(&delta, 0, 0, -kRowLabelWidth, -kColLabelHeight);
  63.     ChangeSize(&delta, FALSE);
  64.     Offset(kRowLabelWidth, kColLabelHeight, FALSE);
  65.     
  66.         // Specify gray row and column borders for the cells
  67.     
  68.     SetRowBorders(1, patCopy, &qd.gray);
  69.     SetColBorders(1, patCopy, &qd.gray);
  70.     
  71.         // set selection behavior so dragging selects rectangular areas
  72.     
  73.     SetSelectionFlags(selDragRects);
  74.         
  75.     itsRowLabels = rowLabels;
  76.     itsColLabels = colLabels;
  77.     
  78.         // link the row and column labels to this table
  79.     
  80.     itsRowLabels->SetTable(this);
  81.     itsColLabels->SetTable(this);
  82.     
  83.         // get our cursor
  84.  
  85.     plusCursor = GetCursor(kPlusCursor);
  86.     FailNILRes(plusCursor);
  87.     
  88. }
  89.  
  90. /******************************************************************************
  91.  GetCellText {OVERRIDE}
  92.  
  93.      We have no data, so just set the text to nothing.
  94.      
  95. ******************************************************************************/
  96.  
  97. void CDemoTable::GetCellText(Cell aCell, short availableWidth,
  98.             StringPtr itsText)
  99. {
  100.     Length(itsText) = 0;
  101. }
  102.  
  103. /******************************************************************************
  104.  Scroll {OVERRIDE}
  105.  
  106.      Normally you don't need to override Scroll. Here we do it
  107.      in order to scroll the table along with the row or column headings
  108. ******************************************************************************/
  109.  
  110. void CDemoTable::Scroll(long hDelta, long vDelta, Boolean redraw)
  111. {
  112.         // CTableScroll::ScrollBits scrolls the table and headings
  113.         // in a single ScrollRect call
  114.         
  115.     if (redraw)
  116.         ((CTableScroller*)itsScrollPane)->ScrollBits(hDelta, vDelta);
  117.         
  118.         // Logically scroll the table and the appropriate labels, 
  119.         // without visually scrolling anything on-screen
  120.         
  121.     inherited::Scroll(hDelta, vDelta, FALSE);
  122.     if (vDelta) 
  123.         itsRowLabels->Scroll(0, vDelta, FALSE);
  124.     if (hDelta)
  125.         itsColLabels->Scroll(hDelta, 0, FALSE);
  126.         
  127.         // redraw the window if requested.
  128.         
  129.     if (redraw)
  130.         GetWindow()->Update();
  131. }
  132.  
  133. /******************************************************************************
  134.  AdjustCursor {OVERRIDE}
  135.  
  136.      Set the cursor to the standard spreadsheet plus cursor
  137. ******************************************************************************/
  138.  
  139. void CDemoTable::AdjustCursor(Point where, RgnHandle mouseRgn)
  140. {
  141.     LoadResource((Handle) plusCursor);
  142.     if (*plusCursor)
  143.         SetCursor(*plusCursor);
  144. }
  145.  
  146. /******************************************************************************
  147.  Draw {OVERRIDE}
  148.  
  149.      Normally you don't need to override CTable::Draw - you override
  150.      DrawCell or GetCellText instead. Here we do it in order to fill
  151.      the area outside the cells with a gray pattern.
  152.      
  153. ******************************************************************************/
  154.  
  155. void CDemoTable::Draw(Rect *area)
  156. {
  157.     LongRect    r;
  158.     Rect        qdRect;
  159.     RgnHandle    tmpRgn;
  160.     
  161.         // Get a region consisting of the area to be drawn
  162.         // it is already in QuickDraw coordinates.
  163.         
  164.     RectRgn(gUtilRgn, area);
  165.     
  166.         // Get the intersection of the bounds and frame rects
  167.         // This corresponds to the cells that are visible.
  168.     
  169.     SectLongRect(&bounds, &frame, &r);
  170.     
  171.         // Since that rect is in Frame coordinates, convert it to
  172.         // a rect in QuickDraw coordinates
  173.         
  174.     FrameToQDR(&r, &qdRect);
  175.     
  176.         // Get a region consisting of the above rect
  177.     
  178.     tmpRgn = NewRgn();
  179.     RectRgn(tmpRgn, &qdRect);
  180.     
  181.         // Subtract the visible cell area from the area to be drawn.
  182.         // The region remaining gives use the area to be drawn outside
  183.         // the bounds.
  184.     
  185.     DiffRgn(gUtilRgn, tmpRgn, tmpRgn);
  186.     
  187.         // If it ain't empty, fill it. Then dispose of the temporary region
  188.     
  189.     if (!EmptyRgn(tmpRgn))
  190.         FillRgn(tmpRgn, &qd.gray);
  191.     
  192.     DisposeRgn(tmpRgn);
  193.     
  194.         // inherited::Draw draws the cells
  195.         
  196.     inherited::Draw(area);
  197.     
  198. }
  199.